package org.example.network.ex5;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        //客户端：多次发送数据
        //服务器：接收多次接收数据，并打印

        //1.创建对象绑定 10000 端口
        ServerSocket ss = new ServerSocket(10000);
        //2.等待客户端来连接
        Socket socket = ss.accept();
        //3.读取数据
//        InputStreamReader isr = new InputStreamReader(socket.getInputStream());
        BufferedReader isr = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        int b;
        while ((b = isr.read()) != -1){ // 只要客户端OutputStream没有关闭，则会一直阻塞等待数据
            System.out.print((char)b);
        }
        //4.释放资源
        socket.close();
        ss.close();
    }
}
